/**
 * Created by Jeffli on 2015/12/31.
 */
var iSmart          = {};
//iSmart.height       = parseInt(window.screen.height);
//iSmart.width        = parseInt(window.screen.width);
//iSmart.scenes       = ["loading", "monkey"];
iSmart.currentscene = 0;
iSmart.Status       = {};
iSmart.loadered     = false;
iSmart.Scenes       = [];


//微信广告监控代码
//var wa   = new WxMoment.Analytics({projectName: "20150531MJN"});
var oTip = new WxMoment.OrientationTip();  //开启横屏提示


//屏幕自适应
iSmart.autoClass = function () {
    var w = $('body').width();
    var h = $('body').height()

    var wh = (w / h).toFixed(2)
    if (wh > 0.68) {
        $('body').addClass('less69');
    }

    console.log(w,h,wh);
}


//微信Wxmoment初始化
iSmart.Loader = function () {
    var BasePath = './assets/style/img';
    var loader   = new WxMoment.Loader();

    //加载文件列表
    //loader.addImage(BasePath + '/all.png');

    //进度监听
    loader.addProgressListener(function (e) {
        var percent = Math.round((e.completedCount / e.totalCount) * 100);
        console.log("当前加载了", percent, "%");
        //在这里做 Loading 页面中百分比的显示
    });

    //加载完成
    loader.addCompletionListener(function () {
        //可以在这里隐藏 Loading 页面开始进入主内容页面
    });

    //启动加载
    loader.start();
}


//================
//屏幕切换
//================
iSmart.SliderInit = function () {
    var pageSlider = new WxMoment.PageSlider({
        pages              : $('.screen'),              //必需，需要切换的所有屏
        direction          : 'vertical',                //可选，vertical 或 v 为上下滑动，horizontal 或 h 为左右滑动，默认为 vertical
        currentClass       : 'current',                 //可选, 当前屏的class (方便实现内容的进场动画)，默认值为 'current'
        rememberLastVisited: true,                      //可选，记住上一次访问结束后的索引值，可用于实现页面返回后是否回到上次访问的页面
        animationPlayOnce  : false,                     //可选，切换页面时，动画只执行一次
        oninit             : function () {},            //可选，初始化完成时的回调
        onbeforechange     : function () {},            //可选，开始切换前的回调
        onchange           : function (id) {
            var Execute = iSmart.Scenes[this.index] || function () {console.log('error', this.index)};
            Execute();
        },
        onSwipeUp          : function () {},            //可选，swipeUp 回调
        onSwipeDown        : function () {},            //可选，swipeDown 回调
        onSwipeLeft        : function () {},            //可选，swipeLeft 回调
        onSwipeRight       : function () {}             //可选，swipeRight 回调
    });

    return pageSlider;
}


//===================
//启动运行
//===================
$(document).ready(function () {
    iSmart.autoClass();
    iSmart.Loader();
    iSmart.Slider = iSmart.SliderInit();

    //事件
    $("#NotUser .submit").click(function () {
        iSmart.Slider.moveTo(1,true);
    })

    $("#Login .submit").click(function () {
        iSmart.Slider.moveTo(2,true);
    })

    $("#Luck .gift").click(function () {
        iSmart.Slider.moveTo(3);
    })


});


